//实现endsWith方法
String.prototype.endsWith=function(str){
    if(str==null||str==""||this.length==0||str.length>this.length)
        return false;
    if(this.substring(this.length-str.length)==str)
        return true;
    else
        return false;
    return true;
};
//初始化
var File = {
};
//添加子节点
File.addFileListChildNodes = function (nodeId, fileName, fileId) {
    var childrenHtml = File.bulidChileHtml(fileName, fileId);
    $("#"+nodeId).append(childrenHtml);
};
//删除子节点
File.removeFileListChildNodes = function (fileId) {
    $("#"+fileId).remove();
};

File.bulidChileHtml = function (fileName, fileId) {
    var iconclass = File.getFileTypeIcon(fileName);

    var childrenHtml = "<div id='"+ fileId +"'>"
        + "<span class='iconfont "+ iconclass +"'></span>"
        + "<span class='filelistName' title='"+fileName+"'>"+ fileName +"</span>"
        + "<span class='iconfont icon-delete' title='删除' onclick=\"File.removeFileListChildNodes('" + fileId +"')\"></span>"
        + "</div>";
    return childrenHtml;
}

File.getFileTypeIcon = function (fileName) {
    var iconclass = "icon-file";
    if(fileName.endsWith(".doc") || fileName.endsWith(".docx")){
        iconclass = "icon-word";
    }else if(fileName.endsWith(".xls") || fileName.endsWith(".xlsx")){
        iconclass = "icon-xls";
    }else if(fileName.endsWith(".ppt") || fileName.endsWith(".pptx")){
        iconclass = "icon-ppt";
    }else if(fileName.endsWith(".pdf")){
        iconclass = "icon-pdf";
    }
    return iconclass;
}
